<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@include file="/WEB-INF/jspf/must/basePath.jspf" %>
<!--后台UI组件Start-->
<%@include file="/WEB-INF/jspf/zj/ligerui/LigerUI.jspf" %>
<%--<%@include file="/WEB-INF/jspf/zj/ligerui/LigerUI_form.jspf" %>--%>
<!--后台UI组件End-->
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
        <script src="dc_manager/base/scheme/combo/fl/js/combofl_treeMenu.js" type="text/javascript"></script>
        <script type="text/javascript">
//-------------------------------全局变量-------------------------------------------------
            var UPDATE;
            var GRID;
            var ADD;
            $(function () {
                f_dc_base_combofl_menuTree("divID_Tree", f_combofl_choose);
                GRID = $("#divID_GRID").ligerGrid({
                    columns: [
//                        {display: 'flid', name: 'flid', width: 90, align: 'left'}
                        {display: '编号', name: 'combo_code', width: 90, align: 'left'}
                        , {display: '名称', name: 'combo_name', width: 90, align: 'left'}
                        , {display: '有效', name: 'combo_style', width: 90, align: 'left'}
                        , {display: '价格', name: 'combo_price', width: 90, align: 'left'}
                        , {display: '原装价格', name: 'combo_listPriceSum', width: 90, align: 'left'}
                        , {display: '限购', name: 'combo_number', width: 90, align: 'left'}
                        , {display: '说明', name: 'combo_info', width: 90, align: 'left'}
                    ]
//                    , enabledEdit: true
                    , usePager: false
                    , url: 'weixinkeji/dev/dc/base/scheme/combo/combo/s/manager.imy'
                    , width: '660px'
                    , height: '97%'
                    , detail: {onShowDetail: f_showComboB}
                    , onSelectRow: resetshowComboBImg
                });
                function f_showComboB(row, detailPanel, callback) {
                    var grid = document.createElement('div');
                    $(detailPanel).append(grid);
                    $(grid).css('margin', 10).ligerGrid({
                        columns: [
                            {display: '食物ID', name: 'food_id', hide: true}
                            , {display: '名称', name: 'food_name', width: 130, align: 'left'}
                            , {display: '编码', name: 'food_code', width: 110, align: 'left', editor: {type: 'text'}}
                            , {display: '单价', name: 'food_price', width: 60, align: 'left', editor: {type: 'text'}}//带出食物档案的价格。可以再次调整
                            , {display: '数量', name: 'food_number', width: 60, align: 'left', type: 'float', editor: {type: 'float'}}
                            , {display: '金额', name: 'food_priceSum', width: 90, align: 'left', type: 'float'}//单价*数量
                            , {display: '单位ID', name: 'unit_id', hide: true}
                            , {display: '单位', name: 'unit_name', width: 40, align: 'left'}
                        ]
                        , url: 'weixinkeji/dev/dc/base/scheme/combo/combob/s/manager.imy?combo_id=' + row.combo_id
                        , showTitle: false
                        , usePager: false
                        , columnWidth: 60
                        , onAfterShowData: callback
                        , frozen: false
                        , onSelectRow: showComboBImg
                    });
                }
                $("#toptoolbar").ligerToolBar({items: [
                        {text: '增加', click: add}
                        , {line: true}
                        , {text: '修改', click: update}
                        , {line: true}
                        , {text: '删除', click: dell}
                    ]});
            });
//-------------------------------GRID列函数-----------------------------------------------
            function f_toEmptyByMyCodeOrName() {
                $("#SELECT_CODE").val("");
                $("#SELECT_NAME").val("");
            }
            function f_selectByMyCodeOrName() {
                addImgToHtml();
                removeMyParm();
                var code = $.trim($("#SELECT_CODE").val());
                var name = $.trim($("#SELECT_NAME").val());
                var style = $.trim($("#SELECT_STYLE").val());
                var andor = $.trim($("#SELECT_ANDOR").val());
                f_check(code, "combo_code");
                f_check(name, "combo_name");
                f_check(style, "combo_style");
                f_check(andor, "andor");
                GRID.reload();
                function f_check(v, name) {
                    if (null == v || v.length == 0) {
                        GRID.removeParm(name);
                    } else {
                        GRID.setParm(name, v);
                    }
                }
            }
            function removeMyParm() {
                GRID.removeParm("combo_code");
                GRID.removeParm("combo_name");
                GRID.removeParm("combo_style");
                GRID.removeParm("andor");
                GRID.removeParm("flid");
            }
            function f_combofl_choose(d, target) {
                addImgToHtml();
                removeMyParm();
                GRID.setParm("flid", getMyNodeID("flid", d.data));
                GRID.reload();
            }
            function showComboBImg(rowdata, rowid, rowobj) {
                addImgToHtml("<img src=\"" + rowdata.food_img + "\" width=\"200px\" height=\"200px\">");
            }
            function resetshowComboBImg(rowdata, rowid, rowobj) {
                addImgToHtml(rowdata.combo_info);
            }
            function addImgToHtml(img) {
                $("#showIMG").html(null == img ? "" : img);
            }
//-------------------------------增删改操作-----------------------------------------------
            function add() {
                ADD = openURL_Event("套餐添加", ADD, "dc_manager/base/scheme/combo/combo_A.jsp", 400, 900, f_d);
                ADD.max();
                function f_d() {
                    ADD = null;
                    GRID.reload();
                }
            }
            function update() {
                var row = GRID.getSelectedRow();
                if (!row) {
                    msg_tip("错误", "请选择行");
                    return;
                } else if (row.combo_id.length > 10) {
                    UPDATE = openURL_Event("套餐修改", UPDATE, "weixinkeji/dev/dc/base/scheme/combo/combo/adu/update.imy?id=" + row.combo_id, 400, 900, f_d);
                    UPDATE.max();
                }
                function f_d() {
                    UPDATE = null;
                    GRID.reload();
                }
            }
            function dell() {
                var rows = GRID.getSelectedRows();
                var ids = "";
                for (var i = 0; i < rows.length; i++) {
                    ids = ids + "," + rows[i].combo_id;
                }
                ids = ids.substring(1);
                if (rows.length < 1) {
                    msg_tip("操作提示", "请选择行", 200, 50);
                    return;
                } else {
                    if (post_json("weixinkeji/dev/dc/base/scheme/combo/combo/adu/dell.imy", {"id": ids})) {
                        GRID.reload();
                    }
                }
            }
        </script>
    </head>
    <body>  
        <div id="toptoolbar"></div> 
        <div>
            <div id="divID_Tree" style="float: left;width: 200px">---</div>
            <div id="divID_GRID" style="float: left"></div>
            <div style="float: left">
                <div style="height:255px;width: 250px; background-color: #00B83F">
                    <table>
                        <tr>
                            <td>编码</td><td><input type="text" id="SELECT_CODE" name="combo_name"></td>  
                        </tr>
                        <tr>  
                            <td>名称</td><td><input type="text" id="SELECT_NAME" name="combo_code"></td> 
                        </tr>
                        <tr>  
                            <td>上架</td>
                            <td>  
                                <select name="combo_style" id="SELECT_STYLE">
                                    <option value="">不限</option>
                                    <option value="1">生效</option>
                                    <option value="0">失效</option>
                                </select>
                            </td>
                        </tr>
                        <tr>  
                            <td>条件间</td>
                            <td>  
                                <select name="combo_andor" id="SELECT_ANDOR">
                                    <option value="1">条件之间是并且关系</option>
                                    <option value="0">条件之间是或者关系</option>
                                </select>
                            </td>
                        </tr>
                        <tr>
                            <td></td><td><button onclick="f_selectByMyCodeOrName()">查询</button><button onclick="f_toEmptyByMyCodeOrName()">清空输入</button></td>
                        </tr>
                    </table>

                </div>
                <div id="showIMG" style="overflow:auto">

                </div>
            </div>
        </div>
    </body>
</html>
